/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.nanosl.norg.ent;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Thilina
 */
@Entity
@Table(name = "attendance")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Attendance.findAll", query = "SELECT a FROM Attendance a"),
    @NamedQuery(name = "Attendance.findByTimeIn", query = "SELECT a FROM Attendance a WHERE a.attendancePK.timeIn = :timeIn"),
    @NamedQuery(name = "Attendance.findByTimeOut", query = "SELECT a FROM Attendance a WHERE a.timeOut = :timeOut"),
    @NamedQuery(name = "Attendance.findByEmployeeId", query = "SELECT a FROM Attendance a WHERE a.attendancePK.employeeId = :employeeId"),
    @NamedQuery(name = "Attendance.findByEmployeeOrganizationId", query = "SELECT a FROM Attendance a WHERE a.attendancePK.employeeOrganizationId = :employeeOrganizationId")})
public class Attendance implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected AttendancePK attendancePK;
    @Column(name = "time_out")
    @Temporal(TemporalType.TIMESTAMP)
    private Date timeOut;
    @JoinColumns({
        @JoinColumn(name = "employee_id", referencedColumnName = "id", insertable = false, updatable = false),
        @JoinColumn(name = "employee_organization_id", referencedColumnName = "organization_id", insertable = false, updatable = false)})
    @ManyToOne(optional = false)
    private Employee employee;

    public Attendance() {
    }

    public Attendance(AttendancePK attendancePK) {
        this.attendancePK = attendancePK;
    }

    public Attendance(Date timeIn, String employeeId, String employeeOrganizationId) {
        this.attendancePK = new AttendancePK(timeIn, employeeId, employeeOrganizationId);
    }

    public AttendancePK getAttendancePK() {
        return attendancePK;
    }

    public void setAttendancePK(AttendancePK attendancePK) {
        this.attendancePK = attendancePK;
    }

    public Date getTimeOut() {
        return timeOut;
    }

    public void setTimeOut(Date timeOut) {
        this.timeOut = timeOut;
    }

    public Employee getEmployee() {
        return employee;
    }

    public void setEmployee(Employee employee) {
        this.employee = employee;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (attendancePK != null ? attendancePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Attendance)) {
            return false;
        }
        Attendance other = (Attendance) object;
        if ((this.attendancePK == null && other.attendancePK != null) || (this.attendancePK != null && !this.attendancePK.equals(other.attendancePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.nanosl.norg.ent.Attendance[ attendancePK=" + attendancePK + " ]";
    }
    
}
